package com.data;

import com.data.Login;
import com.utils.DBUtil;

import java.sql.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserDAO{

    public Login check(String name,String password) {
        Login login=null;
        Map<String, Object> whereMap =new HashMap<>();
        Map<String, Object> map = null;
        whereMap.put("uName", name);
        whereMap.put("uPw", password);
        try {
            List<Map<String, Object>> list = DBUtil.query("user",whereMap);
                map = list.get(0);
                login = new Login((String)map.get("uName"), (String)map.get("uPw"));
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e){
            e.printStackTrace();
        }
        return login;
    }
    public int getUid(String name,String password){
        int uId=1;
        Map<String, Object> whereMap =new HashMap<>();
        Map<String, Object> map = null;
        whereMap.put("uName", name);
        whereMap.put("uPw", password);
        try {
            List<Map<String, Object>> list = DBUtil.query("user",whereMap);
            map = list.get(0);
            uId=((Integer)map.get("uId")).intValue();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (Exception e){
            e.printStackTrace();
        }
        return uId;

    }
}

